#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

string getDigitRoot(string number)
{
    while (number.size() != 1)
    {
        int tmp = 0;
        for (auto& num : number)
        {
            tmp += num - '0';
        }
        number = to_string(tmp);
    }
    return number;
}

int main()
{
    string num;
    while (cin >> num)
    {
        cout << getDigitRoot(num) << endl;
    }
    return 0;
}